#!/bin/sh
if [ ! -f "/root/.ip" ];then
  touch /root/.ip
fi
ip_info=$(curl cip.cc)
if [ -n "$ip_info" ];then
  ip=$(echo $ip_info | cut -d " " -f 3)
  CURRENT_IP=$(cat /root/.ip)
  if [ -n "$ip" ] && [ "$ip" != "$CURRENT_IP" ];
  then
    echo $ip > /root/.ip
    #sendemail -f "NEW IP <$EMAIL_USERNAME>" -t $EMAIL_USERNAME -s "$EMAIL_SMTP_HOST:$EMAIL_SMTP_PORT" -u "NEW IP-$ip" -xu $EMAIL_USERNAME -xp $EMAIL_PASSWORD -m $ip_info
    (
    echo "From: $USERNAME"
    echo "To: $EMAIL"
    echo "Subject: 新IP-$ip"
    echo
    echo "$ip_info"
    echo
    ) | sendmail -f $USERNAME -t $EMAIL -S $SMTP_HOST mail.txt -au$USERNAME -ap$PASSWORD
  fi
fi